| Total Complexity | 10 |
| Total Lines | 59 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | import Xdebug from '../extensions/php/xdebug' |
||
| 3 | |||
| 4 | class XdebugController { |
||
| 5 | |||
| 6 | /** |
||
| 7 | * Switch the service to the given version. |
||
| 8 | */ |
||
| 9 | execute = async (status: string): Promise<boolean> => { |
||
| 10 | if (status !== 'on' && status !== 'off') { |
||
| 11 | console.log(`Invalid status. Please provide status 'on' or 'off'.`) |
||
| 12 | return false |
||
| 13 | } |
||
| 14 | |||
| 15 | const xdebug = new Xdebug() |
||
| 16 | let restart = false |
||
| 17 | |||
| 18 | if (status === 'on') { |
||
| 19 | restart = await this.enable(xdebug) |
||
| 20 | } |
||
| 21 | |||
| 22 | if (status === 'off') { |
||
| 23 | restart = await this.disable(xdebug) |
||
| 24 | } |
||
| 25 | |||
| 26 | if (restart) { |
||
| 27 | const php = await getLinkedPhpVersion() |
||
| 28 | await php.restart() |
||
| 29 | } |
||
| 30 | |||
| 31 | return true |
||
| 32 | } |
||
| 33 | |||
| 34 | enable = async (xdebug: Xdebug): Promise<boolean> => { |
||
| 35 | if (!(await xdebug.isInstalled())) { |
||
| 36 | console.log('Extension xdebug is not installed. Installing now...') |
||
| 37 | await xdebug.install() |
||
| 38 | } |
||
| 39 | |||
| 40 | // TODO: Enable auto start configuration for xdebug. |
||
| 41 | |||
| 42 | console.log('Enabling xdebug...') |
||
| 43 | await xdebug.enable() |
||
| 44 | |||
| 45 | return true |
||
| 46 | } |
||
| 47 | |||
| 48 | disable = async (xdebug: Xdebug): Promise<boolean> => { |
||
| 49 | if (!(await xdebug.isInstalled())) { |
||
| 50 | console.log('Extension xdebug is not installed. We do not need to disable it then...') |
||
| 51 | return false |
||
| 52 | } |
||
| 53 | |||
| 54 | if (!(await xdebug.isEnabled())) { |
||
| 55 | console.log('Extension xdebug is not enabled.') |
||
| 56 | return false |
||
| 57 | } |
||
| 58 | |||
| 59 | await xdebug.disable() |
||
| 60 | |||
| 61 | return true |
||
| 62 | } |
||
| 66 | export default XdebugController |